﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GeoSketch2.Archaeo
{
    public partial class NewProjectForm : Form
    {
        Form MDIParent;

        public NewProjectForm(Form MDIParent)
        {
            InitializeComponent();
            this.MDIParent = MDIParent;

            ComboBox_DescriptionSheetModel.SelectedIndex = 0;
        }

        private void Button_Browse_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = Vars.Setup.FileIO.GSK.OpenSaveDialogDefaultExtensionFilter;
            sfd.Title = "Choose the filename of the project...";
            sfd.AddExtension = true;
            sfd.OverwritePrompt = false;
            DialogResult dr = sfd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                TextBox_Filename.Text = sfd.FileName;
            }
        }

        private void Button_OK_Click(object sender, EventArgs e)
        {
            ArchaeoProject Project = new ArchaeoProject(new SoilSheetParksCanada());

            Project.ProjectDirectory = Path.GetDirectoryName(TextBox_Filename.Text);

            if (TextBox_Archaeologist.Text != "")
            {
                Project.ArchaeologistsList.Add(TextBox_Archaeologist.Text);
                Project.MainSite.ArchaeologistName = TextBox_Archaeologist.Text;
            }

            DialogResult dr = DialogResult.Yes;

            if (File.Exists(TextBox_Filename.Text))
            {
                dr = MessageBox.Show("File already exists, overwrite?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            }

            if (dr == DialogResult.Yes)
            {
                Project.SaveToGSK(TextBox_Filename.Text);
                Directory.CreateDirectory(Project.ProjectDirectory + "\\Images");
                DrawingForm df = new DrawingForm(this.MDIParent, Project, TextBox_Filename.Text);
                df.Show();
                this.Close();
            }
        }

        private void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
